<template>
<!-- 预算调整单 -->
<section class="content-box">
	<div v-if="isshowList">
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-form class="title cover">
				<h2>预算调整单</h2>
				<el-form-item>
					<el-button size="small" class="el-icon-plus" @click="handleAdd">&nbsp;新建&nbsp; </el-button>
				</el-form-item>
        <el-form-item>
          <el-button size="small" @click="search" class="el-icon-search">&nbsp;查询</el-button>
        </el-form-item>
			</el-form>
		</el-col>
    <!-- <el-col :span="24" class="SuppC-toolbar">
      <el-form class="title">
        <div>
          <h2>预算调整单</h2>
          <img @click="handleAdd" class="SuppC-common-icon" src="../../../static/content/images/Common/common-add.png" alt=""/>
        </div>
        <el-form-item class="cover">
          <div class="list-img" @click="search">
            <img class="SuppC-common-icon" src="../../../static/content/images/Common/common-query.png" alt=""/>
            <span>查询</span>
          </div>
        </el-form-item>
      </el-form>
    </el-col> -->
		<!--列表-->
		<!-- <el-table v-if="budgetAdjustList" :data="budgetAdjustList" highlight-current-row v-loading="loading" element-loading-text="正在加载中">
			<el-table-column label="序号" type="index" width="100" sortable>
      </el-table-column>
      <el-table-column prop="BA_DocNO" label="单号" sortable>
			</el-table-column>
			<el-table-column prop="Dept_Name" label="部门">
			</el-table-column>
			<el-table-column prop="UserName" label="编制人">
			</el-table-column>
			<el-table-column prop="BA_Abstract" label="标题" show-overflow-tooltip min-width="300">
			</el-table-column>
			<el-table-column prop="DocStatus" label="状态" sortable>
			</el-table-column>
			<el-table-column label="操作" width="200">
				<template slot-scope="scope">
					<el-button-group>
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">&#12288;编辑&#12288;</el-button>
            //<el-button v-if="scope.row.DocStatus==='待审核'" type="info" size="small" @click="repeal(scope.$index, scope.row)">&#12288;撤销&#12288;</el-button>
            <el-button size="small" @click="checkflowRow(scope.$index, scope.row)">查看流程</el-button>
            <el-button size="small" v-if="scope.row.DocStatus==`新建`" @click="handleDel(scope.$index, scope.row)">&#12288;删除&#12288;</el-button>
					</el-button-group>
        </template>
			</el-table-column>
		</el-table> -->
    <el-table v-if="budgetAdjustList" :data="budgetAdjustList" @row-dblclick="handleEdit" @cell-mouse-enter="cellMouseEnterFn" @cell-mouse-leave="cellMouseLeaveFn" highlight-current-row v-loading="loading" element-loading-text="正在加载中" style="100%">
			<el-table-column prop="BA_DocDate" label="日期" :formatter="formatDate" sortable>
      </el-table-column>
      <el-table-column prop="BA_DocNO" label="单号" sortable>
			</el-table-column>
			<el-table-column prop="BA_Abstract" label="业务描述" show-overflow-tooltip min-width="150">
			</el-table-column>
			<el-table-column prop="DocStatus" label="状态" sortable>
			</el-table-column>
			<el-table-column label="操作" width="200">
				<template slot-scope="scope">
					<!-- <el-button-group>
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">&#12288;编辑&#12288;</el-button>
            <el-button size="small" @click="checkflowRow(scope.$index, scope.row)">查看流程</el-button>
            <el-button size="small" v-if="scope.row.DocStatus==`新建`" @click="handleDel(scope.$index, scope.row)">&#12288;删除&#12288;</el-button>
					</el-button-group> -->
          <div v-if="scope.row.BA_DocNO==mouse_enter_Rcv_DocNO">
          <!-- <div> -->
              <div v-if="scope.row.DocStatus!=='新建'" class="list-img" @click.stop="checkflowRow(scope.$index, scope.row)">
                <!-- 查看流程 -->
                <img class="common-icon" src="../../../static/content/images/Common/common-flow.png" alt=""/>
              </div>
              <div v-if="scope.row.DocStatus==='新建'" class="list-img" @click.stop="handleDel(scope.$index, scope.row)">
                <!-- 删除 -->
                <img class="common-icon" src="../../../static/content/images/Common/common-list-dele.png" alt=""/>
              </div>
              <div v-if="scope.row.AttachmentCount>0" class="list-img">
                <!-- 附件 -->
                <img class="common-icon" src="../../../static/content/images/Common/common-attach.png" alt=""/>
              </div>
            </div> 
        </template>
			</el-table-column>
		</el-table>
		<!--流程图-->
		<el-dialog title="流程执行情况" :visible.sync="checkflowRowVisible" :modal-append-to-body="false" align="center">
			<el-table :data="docRowView" header-align="center" v-loading="docViewloading" element-loading-text="拼命刷新中...">
				<el-table-column property="PlanUser" label="操作人"></el-table-column>
				<el-table-column property="StepName" label="步骤名称"></el-table-column>
				<el-table-column property="OpDate" label="时间"></el-table-column>
				<el-table-column property="OpRemark" label="备注"></el-table-column>
			</el-table>
		</el-dialog>
	</div>
	<!--新建页面-->
	<div v-if="isshowAdd">
		<!-- 导航条 -->
			<div class="flex-top">
				<div>
					<i class="el-icon-arrow-left back" @click="addToBack"></i>
					<span style="font-size:20px;vertical-align:middle;margin:0 10px;">
						预算调整单 </span>
					<!-- <small>
						<span>状态：</span>
						<el-tag type="success">新增</el-tag>
					</small> -->
				</div>
				<!-- 右侧 -->
				<div class="flex">
					<span class="wrapper cover">
            <el-button-group>
              <!-- <el-button type="info" @click="addSave">
                <i class="icon iconfont icon-baocun"></i> 保存
              </el-button> -->
              <el-button size="small" @click="openUploadDialog">
                <i class="icon iconfont icon-shangchuan"></i> 附件
              </el-button> 
              <el-button size="small" @click="addSubmit">
                <i class="icon iconfont icon-tijiao"></i> 提交
              </el-button>
            </el-button-group>
					</span>
				</div>
			</div>
      <div class="flex-content">
        <!-- 中部 -->
        <main class="main">
          <div class="main-left">
            <div v-if="DocNo">					
              <h3>单号:</h3>
              <strong>{{DocNo}}</strong>
            </div>
            <div>
              <h3>日期：</h3>
              <div class="flex">
                <el-date-picker type="date" placeholder="选择日期" v-model="docDate">
                </el-date-picker>
              </div>
            </div>
          </div>
          <div class="main-right">
            <div class="left-form" style="width: 100%;">
              <el-row>
                <el-col :span="12">
                  <span class="pay">预算类型</span>
                  <el-select v-model="BudgetType" style="margin-left:20px;" @change.native="Clear()">
                    <el-option v-for="(items,index) in BudgetTypeList" :key="index" :value="items.Code" :label="items.Name">
                    </el-option>
                  </el-select>
                </el-col>
                <el-col :span="12">
                  <span class="pay">调整方式</span>
                  <el-select v-model="AdjustModel" style="margin-left:20px;">
                    <el-option v-for="(items,index) in AdjustModelList" :key="index" :value="items.Code" :label="items.Name">
                    </el-option>
                  </el-select>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <span class="pay">业务描述</span>
                  <div style="display: inline-block;width: 75%; margin-left:20px;" >
                    <el-input
                    type="textarea"
                    :rows="3"
                    placeholder="请输入内容"
                    v-model="describe" 
                    class="textarea-title">
                    </el-input>
                  </div>
                </el-col>
              </el-row>
            </div>
            <div class="right-form">
              <!-- <span>业务描述</span><br><br>
              <el-input
              type="textarea"
              :rows="10"
              placeholder="请输入内容"
              v-model="describe" 
              class="textarea-title heigth-textarea-100">
              </el-input> -->
            </div>
          </div>
        </main>
        <!--底部 预算明细 -->
        <div class="budget-two">
          <div class="padding-size-10">
            <div style="padding:10px;">     
              <span><i class="icon iconfont icon-iconfontcolor52"></i> 预算明细</span>
              <!-- &#x3000;
              合计：<span class="Count">{{Count}}</span>&#12288; 
              <el-button class="add-button" size="small" @click="addlist">添加行</el-button> -->
              <div class="SuppC-Nas-itemRight" style="height: auto !important;">
                <el-tooltip class="item" effect="dark" content="导入" placement="top-start" style="margin-right:20px;">
                  <span class="SuppC-common-icon">
                    <label for="file2"><img src="../../../static/content/images/Common/common-import.png" alt=""></label>
                    <input name="file" id="file2" type="file" accept="*" @change="importExcel" />
                  </span>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="导出" placement="top-start">
                  <span class="SuppC-common-icon"  @click="export2Excel">
                    <img src="../../../static/content/images/Common/common-export.png" alt="">
                  </span>
                </el-tooltip>
              </div>              
            </div>
            <table class="cusTable" border="1" width="100%">
              <tr>
                <!-- <th>金额</th>
                <th>月份</th>
                <th>费用承担部门</th>
                <th>费用类型</th>
                <th>预算余额</th>
                <th>操作</th> -->
                <th>操作</th>
                <th>月份</th>
                <th>费用承担部门</th>
                <th colspan="2">费用类型</th>
                <!-- <th>预算余额</th> -->
                <th>金额</th>
              </tr>
              <tr v-for="(i,index) in detail" :key="index" class="cusTable-tr">
                <!-- 遍历初始化的detail添加行空数据 -->
                <td width="8%">
                  <!-- <el-button size="small" @click="handleDelete(index)" type="danger" class="dele">删除</el-button> -->
                  <div class="oper-btn-wrapper">
                        <button size="small" @click="handleDelete(index)" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-dele.png"/></button>
                        <button size="small" @click="addlist" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-add.png"/></button>
                    </div>
                </td>
                <td width="8%">
                  <el-select class="formVal full-box" v-model="i.Month" @change="changeMonth(index,i.Month)">
                    <el-option v-for="(item,index) in Month" :value="item.Code" :key="index" :label="item.Name">
                    </el-option>
                  </el-select>
                </td>
                <td width="20%">
                  <!-- <el-select class="formVal full-box" v-model="i.YBL_Department" @change="changeSelect(index,i.YBL_Department)">
                    <el-option v-for="(item,index) in bears" :value="item.CODE" :key="index" :label="item.FULLNAME">
                    </el-option>
                  </el-select> -->
                  <el-select class="formVal full-box" v-model="i.YBL_Department" @visible-change="changeSelect(index,i.YBL_Department,$event)">
                    <!-- v-model => 费用承担部门 -->
                    <el-option v-for="(item,index) in bears" :value="item.CODE" :key="index" :label="item.FULLNAME">
                      <!-- 部门名称 -->
                    </el-option>
                  </el-select>
                </td>
                <td>
                  <!-- BorrowLine_YBL 费用类型iD -->
                  <el-select class="formVal full-box" @change="ChangeMoney(index)" v-model="i.BorrowLine_YBL">   
                    <!-- v-model => 费用类型 -->
                    <el-option v-for="(item,index) in i.costTypes" :value="item.ID" :key="item.ID" :label="item.BudgetItem_Name">
                    </el-option>
                  </el-select>
                </td>
                <td width="15%" class="font-budgetBalance">
                  <span class="budgetBalance">余额：{{i.balance}}</span>
                  <!-- 预算金额 -->
                </td>
                <td  width="15%">
                  <el-input type="text" @blur="doToFixed(i,'BorrowLine_BorrowMoney')" @keydown.enter.native="addlist" @keyup.native="onlyNumObjFn(i,'BorrowLine_BorrowMoney')" v-model="i.BorrowLine_BorrowMoney" class="formval-money full-box"></el-input>
                  <!-- v-model => 金额 -->
                </td>
              </tr>
            </table>
            <div class="clearfloat">
              <div class="total-box">合计：<span class="Count-text">{{Count}}</span></div>
            </div>   
          </div>
        </div>
      </div>
	</div>
  <!-- 
		编辑/待审核/已审核/已发起/未发起 界面 		
	-->
	<div v-if="isshowEdit">
    <!-- 导航条 -->
		<div class="flex-top">
			<div>
				<i class="el-icon-arrow-left back" @click="editToBack"></i>
				<span style="font-size:20px;vertical-align:middle;margin:0 10px;">
					预算调整单</span>
				<!-- <small>
					<span>状态：</span>
					<el-tag type="success">{{Type===1?'修改':Type===2?'查看':Type===3?'待审核':''}}</el-tag>
				</small> -->
			</div>
      <!-- 右侧 -->
			<div class="flex">
				<span class="wrapper cover">
          <el-button-group>
            <el-button size="small" @click="openUploadDialog" :disabled="fjBtnDisabled">
                <i class="icon iconfont icon-shangchuan"></i>&nbsp;附件
            </el-button> 
            <el-button  size="small" @click="checkflow" v-if="Type===2||Type===3">
              <i class="icon iconfont icon-liucheng"></i>&nbsp;流程
            </el-button>
            <el-button size="small" v-if="Type===3" @click="rejectBudget">
              <i class="icon iconfont icon-bohui"></i>&nbsp;驳回
            </el-button>
            <!-- <el-button type="info" @click="editSave" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-baocun"></i>保存
            </el-button> -->
            <el-button size="small" @click="editSubmit" v-if="Type===0||Type===1" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-tijiao"></i>&nbsp;提交
            </el-button>
            <el-button size="small" @click="auditBudget" v-if="Type===3" :disabled="Type===1||Type===2">
              <i class="icon iconfont icon-shenhe"></i>&nbsp;同意
            </el-button>
          </el-button-group>
				</span>
			</div>
    </div>
      <!--流程图-->
			<el-dialog title="流程执行情况" :visible.sync="checkflowVisible" :modal-append-to-body="false" align="center">
				<el-table :data="docView" header-align="center" v-loading="docViewloading" element-loading-text="拼命刷新中...">
					<el-table-column property="PlanUser" label="操作人"></el-table-column>
					<el-table-column property="StepName" label="步骤名称"></el-table-column>
					<el-table-column property="OpDate" label="时间"></el-table-column>
					<el-table-column property="OpRemark" label="备注"></el-table-column>
				</el-table>
      </el-dialog>
      <div class="flex-content">
        <!-- 中部 -->
        <main class="main">
          <div class="main-left">
            <div v-if="Type == 1 || Type == 2 || Type == 3">
              <h3>单号:</h3>
              <strong>{{DocNo}}</strong>
            </div>
            <div>
            <h3>日期：</h3>
            <div class="flex">
              <el-date-picker :disabled="Type===2||Type===3"  type="date" placeholder="选择日期" v-model="docDate">
              </el-date-picker>
            </div>
            </div>
          </div>
          <div class="main-right">
            <div class="left-form" style="width: 100%;">
              <!-- <el-row>
                <el-col :span="24">
                  <span>预算类型：</span>
                  <el-select v-model="BudgetType" style="margin-left:20px;" @change.native="Clear()">
                    <el-option v-for="(items,index) in BudgetTypeList" :key="index" :value="items.Code" :label="items.Name">
                    </el-option>
                  </el-select>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <span>调整方式：</span>
                  <el-select v-model="AdjustModel" style="margin-left:20px;">
                    <el-option v-for="(items,index) in AdjustModelList" :key="index" :value="items.Code" :label="items.Name">
                    </el-option>
                  </el-select>
                </el-col>
              </el-row> -->
              <el-row>
                <el-col :span="12">
                  <div>
                    <span>预算类型</span>
                    <el-select v-model="BudgetType" :disabled="Type===2||Type===3"  style="margin-left:20px;" @change.native="Clear()">
                      <el-option v-for="(items,index) in BudgetTypeList" :key="index" :value="items.Code" :label="items.Name">
                      </el-option>
                    </el-select>                
                    </div>
                </el-col>
                <el-col :span="12">
                  <div>
                    <span>调整方式</span>
                    <el-select v-model="AdjustModel" :disabled="Type===2||Type===3"  style="margin-left:20px;">
                      <el-option v-for="(items,index) in AdjustModelList" :key="index" :value="items.Code" :label="items.Name">
                      </el-option>
                    </el-select>                  
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <div>
                    <span class="pay">业务描述</span>
                    <div style="display: inline-block;width: 75%; margin-left:20px;">
                      <el-input
                      type="textarea"
                      :rows="3"
                      placeholder="请输入内容"
                      v-model="describe"
                      :disabled="Type===2||Type===3" 
                      class="textarea-title">
                      </el-input> 
                    </div>
                
                  </div>
                </el-col>
              </el-row>
            </div>
            <div class="right-form">
              <!-- <span>业务描述</span><br><br>
              <el-input
              type="textarea"
              :rows="10"
              placeholder="请输入内容"
              v-model="describe" 
              class="textarea-title heigth-textarea-100">
              </el-input> -->
            </div>
          </div>
        </main>
        <!--底部 预算明细 -->
        <div class="budget-two">
          <div class="padding-size-10">
            <div style="padding:10px;">     
              <span><i class="icon iconfont icon-iconfontcolor52"></i> 预算明细</span>
              <!-- &#x3000;
              合计：<span class="Count">{{Count}}</span>&#12288; 
              <el-button class="add-button" size="small" @click="addlist">添加行</el-button> -->
            </div>
            <table class="cusTable" border="1">
              <tr>
                <!-- <th>金额</th>
                <th>月份</th>
                <th>费用承担部门</th>
                <th>费用类型</th>
                <th>预算余额</th>
                <th>操作</th> -->
                <th>操作</th>
                <th>月份</th>
                <th>费用承担部门</th>
                <th colspan="2">费用类型</th>
                <!-- <th>预算余额</th> -->
                <th>金额</th>
              </tr>
              <tr v-for="(i,index) in detail" :key="index" width="100%" class="cusTable-tr">
                <!-- 遍历初始化的detail添加行空数据 -->
                <td width="8%">
                  <!-- <el-button size="small" @click="handleDelete(index)" type="danger" class="dele" :disabled="Type===2||Type===3">删除</el-button> -->
                    <div class="oper-btn-wrapper" v-if="!(Type===2||Type===3)">
                        <button size="small" @click="handleDelete(index)" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-dele.png"/></button>
                        <button size="small" @click="addlist" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-add.png"/></button>
                    </div>
                </td>
                <td width="8%">
                  <span class="budgetBalance">{{i.Month}}</span>                            
                </td>
                <td width="20%">
                  <span class="budgetBalance">{{i.YBL_Department}}</span>              
                </td>
                <td>
                  <span class="budgetBalance">{{i.BorrowLine_YBL}}</span>
                </td>
                <td width="15%" class="font-budgetBalance">
                  <span class="budgetBalance">余额：{{i.balance}}</span>
                </td>
                <td width="15%">
                  <el-input type="number" v-model.number="i.BorrowLine_BorrowMoney" class="formval-money full-box" :disabled="Type===2||Type===3"></el-input>
                </td>
              </tr>
            </table>
            <div class="clearfloat">
              <div class="total-box">合计：<span class="Count-text">{{Count}}</span></div>
            </div>   
          </div>
        </div>
      </div>
    </div>
    <!--附件-->
    <el-dialog title="附件" :visible.sync="dialogUploadVisible" :modal-append-to-body="false" >
        <label for="file" class="label-file" v-if="Type!=2&&Type!=3"><i class="icon iconfont icon-shangchuan">&nbsp;</i>上传</label>
        <input name="file" id="file" type="file" accept="*" @change="update" multiple/>
        <ul ref="images" style="display:none">
          <li v-for="(item, index) in UploadList" :key="index">
            <!-- <img :src="`http://192.168.1.188:8011/${item.Attachment_Url}`" :alt="item.Attachment_FileName"> -->
            <img :src="item.Attachment_Url" :alt="item.Attachment_FileName">  
          </li>
        </ul>
        <el-table :data="UploadList" header-align="center" id="test">
          <el-table-column property="ID" label="ID" width="100"></el-table-column>
          <el-table-column property="Attachment_UploadDate" label="日期" :formatter="formatUploadDate"></el-table-column>
          <el-table-column property="Attachment_FileName" label="名称" show-overflow-tooltip></el-table-column>          
          <el-table-column label="操作" max-width="100">
            <template slot-scope="scope">
              <div style="display:inline-block;">
                <el-button v-if='isShowPreview(scope.row.Attachment_FileName)' type="info" size="small" @click="preview(scope)">
                  &#12288;<i class="el-icon-search"></i>预览&#12288;
                </el-button>
              </div>
              <a class="down" :href="scope.row.Attachment_Url" :download='scope.row.Attachment_FileName'>下载</a>
              <el-button v-if="Type!=2&&Type!=3" type="danger" size="small" @click="DeleUpload(scope.$index, scope.row)">&#12288;删除&#12288;</el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-dialog>
    <!--查询-->
    <el-dialog title="查询" :visible.sync="dialogSearchVisible" :modal-append-to-body="false" size="tiny">
      <el-form :model="Searchform">
        <el-form-item label="单  号 ：" :label-width="formLabelWidth">
          <el-input v-model="Searchform.DocNo" style="width:262px;"></el-input>
        </el-form-item>
        <el-form-item label="摘  要 ：" :label-width="formLabelWidth">
          <el-input v-model="Searchform.Title" style="width:262px;"></el-input>
        </el-form-item>
        <el-form-item label="状 态 ：" :label-width="formLabelWidth">
          <el-select v-model="Searchform.DocStatus" style="width:262px;" placeholder="请选择">
            <el-option value="" label="全部">全部</el-option>
            <el-option
              v-for="item in StatusOptions"
              :key="item.Code"
              :label="item.Name"
              :value="item.Code">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer cover">
        <el-button size="small" @click="Reset">重 置</el-button>
        <el-button size="small" @click="Query">确 定</el-button>
        <!-- <el-button size="small" @click="dialogSearchVisible = false">取 消</el-button> -->
      </div>
    </el-dialog>
</section>
</template>

<script>
import moment from 'moment';
export default {
  name: "budegetAdjust",
  data() {
    return {
      viewer: null, //viewer对象
      showNum:"",//传过来的参数
      key:"",
      Msg: "", //审核提醒
      isshowList: true,
      isshowAdd: false,
      isshowEdit: false,
      checkflowRowVisible: false, //外面的流程图
      checkflowVisible: false, //里面的流程图
      dialogSearchVisible:false,//查询窗口
      formLabelWidth:'120px',
      StatusOptions:[],//状态列表
      bears: [], //获取费用承担部门数据
      budgetAdjustList: [], //列表
      docRowView: [], //外部流程图列表
      docView: [], //内部流程图列表
      loading: true,
      SFBudgetItem:true,
      docViewloading: false,
      dialogUploadVisible: false,//上传窗口
      docDate: "", //初始化日期
      DocNo:"",//单号
      arrangeMode: "", //调整方式
      describe: "", //业务描述
      budgetDetail:[],//详情
      AdjustModelList: [], //调整方式
      AdjustModel: "",
      BudgetTypeList: [], //预算类型
      BudgetType: "",
      Type: 0, //0添加  1修改 2查看  3待
      detail: [
        {
          BorrowLine_BorrowMoney: '', //金额
          YBL_Department: "", //费用承担部门
          BorrowLine_YBL: "", //费用类型
          balance: "", //预算金额
          Month: 0,
          costTypes: []
        }
      ],
      Searchform: {
          DocNo:'',
          Title:'',
          DocStatus:''
      },
      detailTemp: [], //获取借款单明细
      UploadList: [], //附件列表数据
      Month: [],
      MonthParams: 0,
      //沟通模块
      dialogCommunicationVisible:false,//沟通窗口      
      CommunicationContentList:[],//沟通内容列表
      contentInput:'',//输入内容Model
      acquiescenceImg:'static/content/images/Header-S.png',//默认头像
      LaunchList:[],//沟通对象集合
      launch:[],//沟通对象
      launchChecked:false,//是否允许编辑
      requestEmp:'',//申请人ID
      communiTypes:0,//获取沟通状态
      isshowLauch:false,
      DocType: 203,//单据类型 报销单=301 借款单=302  还款单=303 收入确认单=304  出纳付款=401  出纳收款=402
      mouse_enter_Rcv_DocNO:"",
      fjBtnDisabled: true,//附件按钮置灰true
    };
  },
  methods: {
    export2Excel() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['部门编码', '费用类型编码', '调整月份', '调整金额'];
        const filterVal = ['part-code', 'type-code', 'month', 'money'];
        // const list = this.tableData;
        //const data = this.formatJson(filterVal, list);
        const data = [];
        export_json_to_excel(tHeader, data, '预算调整单明细');
      })
    }, 
    formatJson(filterVal, jsonData) {//导出功能
        console.log(jsonData,'jsonData');
        console.log(filterVal,'filterVal');
    　　return jsonData.map(v => filterVal.map(j => v[j]))
    },    
    importExcel(e) {//导入
      console.log(e.target.files[0],"e")
      let file = e.target.files[0];
      console.log(file,"file")
      let param = new FormData(); //创建form对象
      param.append('file', file, file.name);//通过append向form对象添加数据
      param.append('YBL_BudgetType', '1');//添加form表单中其他数据
      console.log(param,"param"); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
      let config = {
          headers: { 'Content-Type': 'multipart/form-data' }
      };  //添加请求头
      axios.post('importBudgetAdjust', param, config).then(response => {
            // console.log(response)
        if(response.Success){
          //console.log(response.Data,"Data")
          this.importTable(response.Data)
          this.$message({
            message: response.Message,
            type: 'success'
          });
          // console.log(this.tableData1,'11111')
        }else{
          this.$message({
            message: response.Message,
            type: 'warning'
          });	
        }
      })
    },
    importTable(data){
      console.log(data,"data")
      console.log(JSON.parse(data),"dataldkjslj")
      let detailTemp = JSON.parse(data); //明细列表
      this.detail = [];
      let getCostTypePromiseAll = [];
      for (let i = 0; i < detailTemp.length; i++) {
        let {Money:BorrowLine_BorrowMoney,DepartID:YBL_Department,YBLID:BorrowLine_YBL,Month:Month,YBLName:YBLName}=detailTemp[i]
        BorrowLine_BorrowMoney=this.toFixedOriginFn(Number(BorrowLine_BorrowMoney),2);
        this.detail.push({
          BorrowLine_BorrowMoney:BorrowLine_BorrowMoney,
          YBL_Department,
          BorrowLine_YBL:Number(BorrowLine_YBL),
          balance: 0,
          Month:Number(Month),
          costTypes: []
        });
        console.log(this.detail,"detail")
        getCostTypePromiseAll.push(
          this.getCostType(
            this.detail[i].YBL_Department, // 部门id
            this.detail[i].BorrowLine_YBL, //  明细id
            i
          )
        );
      }
      this.SFBudgetItem = false;
      //  获取 费用类型
      Promise.all(getCostTypePromiseAll).then(resultArr => {
        console.log(resultArr,"resultArr")
        // 循环
        for (let i = 0; i < this.detail.length; i++) {
          // 每条明细赋值费用类型数据
          this.detail[i].costTypes = resultArr[i];
          let yes = !1;
          let m = 0; // 费用
          //循环 判断 明细里面的费用类型是不是存在 。
          //BorrowLine_YBL
          resultArr[i].map(item => {
            if (item.ID == this.detail[i].BorrowLine_YBL) {
              yes = !0;
              m = item.YBL_ThisLeaved;
            }
          });
          // 不存在 就取第一个
          if (!yes) {
            this.detail[i].BorrowLine_YBL = resultArr[i][0].ID;
            this.detail[i].balance = resultArr[i][0].YBL_ThisLeaved;
          } else {
            this.detail[i].balance = m;
          }
        }

        this.SFBudgetItem = true;
      });
    },    
    cellMouseEnterFn(...arr){//鼠标移速单元格触发事件
      this.mouse_enter_Rcv_DocNO=arr[0].BA_DocNO
    },
    cellMouseLeaveFn(){
      this.mouse_enter_Rcv_DocNO=""
    }, 
    formatDate(row, column) {
      return row.BA_DocDate.split("T", 1);
    },
    formatUploadDate(row, column) {
      return row.Attachment_UploadDate.split("T", 1);
    },
    async getList() {
      const res = await axios.get("getBudgetAdjustList", {
            page: 1, //一页
            rows: 5000 //显示5000条
      })
      this.loading = true;
      this.budgetAdjustList = res.rows;
      this.loading = false;
    },
    search(){
      this.dialogSearchVisible = true;
      this.getStatusList();
    },
    async getStatusList(){
      this.StatusOptions = await axios.get('getStatusList');
    },
    /*
     *  查询 
     */
    async Query(){
      this.dialogSearchVisible = false;
      let filterName = {
        "groupOp": "AND",
        "rules": [{
          "field": "BA_DocNO",
          "dataType": "string",
          "op": "cn",
          "data": this.Searchform.DocNo || ''
        }, {
          "field": "BA_Abstract",
          "dataType": "string",
          "op": "cn",
          "data": this.Searchform.Title || ''
        },{
          "field": "BA_DocStatus",
          "dataType": "numeric",
          "op": "eq",
          "data": this.Searchform.DocStatus || ''
        }],
        "groups": []
      }
      this.loading = true;
      const res = await axios.post("getBudgetAdjustList", { 
        filter:JSON.stringify(filterName),
        page:this.currentPage,
        rows:this.rows,
      });
      this.total = res.total;//总页数
      this.budgetAdjustList = res.rows;
      this.loading = false;
    },
    Reset(){
      this.Searchform = {
          DocNo:'',
          Title:'',
          DocStatus:''
      }
    },
    // 新建返回到列表页面
    addToBack() {
      this.isshowAdd = false; //新建页面隐藏
      this.isshowList = true; //列表页面显示
      this.getList();
    },
    // 编辑返回列表页面
    editToBack(){
      this.isshowEdit = false; //新建页面隐藏
      this.isshowList = true; //列表页面显示
      this.getList();
    },
    /**
     * 新增页面显示
     */
    handleAdd() {
      this.isshowAdd = true; //新建页面显示
      this.isshowList = false; //列表页面隐藏
      this.isshowEdit= false; //列表页面隐藏
      this.AdjustModel="";
      this.docDate = new Date();
      this.describe = '';
      this.detail = [      
        {
          BorrowLine_BorrowMoney: '', //金额
          YBL_Department: "", //费用承担部门
          BorrowLine_YBL: "", //费用类型
          balance: "", //预算金额
          Month: 0,
        }
      ];
      this.Type = 0;
      this.getbudgetTypeAndArrangeModel();
      this.getMonth(res=>{
        let detail = this.detail;//this.detail是 每行的对象
        detail.forEach((item,index)=>{
          item.Month = res[0].Code;
        })
      });
      this.bear();
    },
    //获得调整方式，预算类型获得调整方式，预算类型
    getbudgetTypeAndArrangeModel(){
      axios
        .get("budgetTypeAndArrangeModel")
        .then(res => {
          this.AdjustModelList = res.AdjustMode; //调整方式
          this.BudgetTypeList = res.BudgetType; //	预算类型
          //this.AdjustModel = res.AdjustMode[0].Code;
          this.BudgetType = res.BudgetType[2].Code;
        })
        .catch(err => {
          console.log(err);
        });
    },
    //获取月份
    getMonth(cb){
      axios
        .get("getMonth")
        .then(res => {
          this.Month = res;
          cb && cb(res);
        })
        .catch(err => {
          console.log(err);
        })
    },
    /*
     *	显示编辑界面
     */
    // handleEdit(index,row){
    handleEdit(...rest) {
      let row=rest[0];  
      if(!row){
        this.showNum = this.$route.query.showNum;        
        this.DocNo = this.$route.query.key;        
      }else{
        this.DocNo = row.BA_DocNO;
      }
      this.isshowEdit = true; //编辑显示
      this.isshowList = false; //列表隐藏 
      this.isshowAdd = false;
      this.AdjustModel="";
      //获得调整方式，预算类型
      this.getbudgetTypeAndArrangeModel();
      //获取月份
      this.getMonth();
      //获取详细信息
      axios
        .get("getBudgetOperation",{key:this.DocNo})
        .then(res => {
          this.Type = res.Type;
          if (this.Type==1) {//修改状态附件按键亮起
            this.fjBtnDisabled=false;
          }else{//查看和待审核状态，有附件数才亮起
            this.fjBtnDisabled = res.FJNum==0?true:false;
          }
          this.budgetDetail = res.entity;
          this.DocNo = this.budgetDetail.BA_DocNO;
          this.docDate = this.budgetDetail.BA_DocDate;
          this.BudgetType = this.budgetDetail.BA_BudgetType;//绑定Code
          this.AdjustModel = this.budgetDetail.BA_AdjustMode;//绑定Code
          this.describe = this.budgetDetail.BA_Abstract;
          axios
          .get('getBudgetAdjustLineTxT',{key:this.DocNo})//这里获取
          .then(res => {
            this.detailTemp = res;//明细列表
            console.log(this.detailTemp,'明细列表');
            this.detail = [];
            for(let i = 0; i<this.detailTemp.length;i++){
              this.detail.push({
                BorrowLine_BorrowMoney:this.detailTemp[i].Money,
                Month:this.detailTemp[i].YBL.Month,
                YBL_Department:this.detailTemp[i].YBL.DepartmentName,
                BorrowLine_YBL:this.detailTemp[i].YBL.BudgetItemName,
                balance:this.detailTemp[i].YBL.ThisLeaved
              })
            }
            console.log(this.detail,'this.detail')
            //判断状态获取沟通
            if(this.communiTypes==1||this.communiTypes==2){ 
              this.dialogCommunicationVisible = true;
              this.isshowLauch = false;
              let all = [
                axios.get('CommunicationContent',{
                  key:this.DocNo,
                  DocType:this.DocType
                }),
                axios.get('LaunchList',{
                  key:this.DocNo,
                  DocType:this.DocType
                }),
              ];
              this.axios.all(all).then(
                this.axios.spread((res1,res2)=>{
                  this.CommunicationContentList = res1;//获得沟通内容
                    for(var i=0;i<this.CommunicationContentList.length;i++){
                      if(this.CommunicationContentList[i].Img==''){//如果是空的
                        const ac = this.acquiescenceImg;
                        this.CommunicationContentList[i].Img = ac;//赋值默认头像
                      }
                    }
                    this.requestEmp = res2.RequestEmp;//申请人ID
                    this.LaunchList = res2.us;//获得沟通对象  
                })
              )   
            }
          })
        })
        .catch(err => {
          console.log(err);
        });
      
      
    },
    /* addSave() {
      let myArr = [];
      let detail = this.detail;
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        BA_DocDate: this.docDate,
        BA_BudgetType: this.BudgetType,
        BA_AdjustMode: this.AdjustModel,
        BA_Abstract: this.describe,
        BA_DocStatus: 1, //1=保存 2=提交
        key: null,
        Budget: this.Budget
      };
      axios
        .post("BudgetAdjustSubmit", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: res.Message,
              type: "success",
              duration:1200
            });
            this.isshowAdd = false;
            this.isshowEdit = false;
            this.isshowList = true;
            this.getList();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration:1500  
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }, */
    addSubmit() {
      let myArr = [];
      console.log(this.detail,"detail")
      //BorrowLine_BorrowMoney BorrowLine_YBL YBL_Department
      this.detail=this.detail.filter(item=>item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department);
      if (this.detail.length==0) {
        this.addlist();
      }      
      let detail = this.detail;
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        BA_DocDate: this.docDate,
        BA_BudgetType: this.BudgetType,
        BA_AdjustMode: this.AdjustModel,
        BA_Abstract: this.describe,
        BA_DocStatus: 2, //1=保存 2=提交
        key: this.DocNo,
        Budget: this.Budget
      };
      axios
        .post("BudgetAdjustSubmit", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: `提交成功`,
              type: "success",
              duration:1200
            });
           /*  if(res.data.DocNO){
              this.DocNo = res.data.DocNO
            } */
            this.isshowAdd = false;
            this.isshowEdit = false;
            this.isshowList = true;
            this.getList();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration:1500  
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    /* editSave(){
      let myArr = [];
      let detail = this.detail;
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        BA_DocDate: this.docDate,
        BA_BudgetType: this.BudgetType,
        BA_AdjustMode: this.AdjustModel,
        BA_Abstract: this.describe,
        BA_DocStatus: 1, //1=保存 2=提交
        key: null,
        Budget: this.Budget
      };
      axios
        .post("BudgetAdjustSubmit", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: res.Message,
              type: "success",
              duration:1200
            });
            this.isshowAdd = false;
            this.isshowEdit = false;
            this.isshowList = true;
            this.getList();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration:1500  
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }, */
    editSubmitForm(){
      let myArr = [];
      let detail = this.detail;
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        BA_DocDate: this.docDate,
        BA_BudgetType: this.BudgetType,
        BA_AdjustMode: this.AdjustModel,
        BA_Abstract: this.describe,
        BA_DocStatus: 2, //1=保存 2=提交
        key: this.DocNo,
        Budget: this.Budget
      };
      axios
        .post("BudgetAdjustSubmit", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: `提交成功`,
              type: "success",
              duration:1200
            });
            /* if(res.data.DocNO){
              this.DocNo = res.data.DocNO
            } */
            this.isshowAdd = false;
            this.isshowEdit = false;
            this.isshowList = true;
            this.getList();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration:1500  
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    editSubmit(){
      this.getState();
      if(this.communiTypes===2){ 
        this.isshowLauch = true;
        this.dialogCommunicationVisible = true;
      } else {
        this.editSubmitForm();
      }
    },
    /**
     * 预算明细添加行
     */
    addlist() {
      this.detail.push({
        BorrowLine_BorrowMoney: '',
        Month: this.Month[0].Code,
        YBL_Department: "",
        BorrowLine_YBL: "",
        balance: "",
        costTypes: [] // 费用类型 数据
      });
    },  
    //沟通窗口打开 
    Communication(){
      this.dialogCommunicationVisible = true;
      this.isshowLauch=false;
      let all = [
          axios.get('CommunicationContent',{
            key:this.DocNo,
            DocType:this.DocType
          }),
          axios.get('LaunchList',{
            key:this.DocNo,
            DocType:this.DocType
          }),
          axios.get('getCommuniState',{
            key:this.DocNo,
            DocType:this.DocType,
            types:this.Type
          })
      ];
      this.axios.all(all).then(
        this.axios.spread((res1,res2,res3)=>{
            this.CommunicationContentList = res1;//获得沟通内容
            for(var i=0;i<this.CommunicationContentList.length;i++){
              if(this.CommunicationContentList[i].Img==''){//如果是空的
                const ac = this.acquiescenceImg;
                this.CommunicationContentList[i].Img = ac;//赋值默认头像
              }
            }
            this.requestEmp = res2.RequestEmp;//申请人ID
            this.LaunchList = res2.us;//获得沟通对象  
            this.communiTypes = res3;//获取沟通状态
        })
      )   
    },
    //允许提交者编辑单据Change事件
    launchChange(e){
      console.log(e,'e');
      if(e){
        console.log(this.requestEmp,'this.requestEmp');
        console.log(this.launch,'this.launch');
        let bo=true;
        for(let i=0;i<this.launch.length;i++)
        { 
          if(this.launch[i]==this.requestEmp)
          bo=false;      
        }
        if(bo)this.launch.push(this.requestEmp);
      }
    },
    //确认后提交
    CommunicationDetermine(){
      if(this.isshowLauch == true)
      {
        this.$confirm('回复沟通单据将会自动提交，不可再编辑!', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           this.Communicate();
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });           
        });
      }else{
        this.Communicate();
      }
    },
    //沟通窗口 确定按钮
    Communicate(){
      let user='';
      for(let i=0;i<this.launch.length;i++){ 
          user+=i!=0?',':'';
          user+=this.launch[i];
      }    
      axios.get('AddCommunicate',{
          key:this.DocNo,
          DocType:this.DocType,
          msg:this.contentInput,
          user:user,
          bj:this.launchChecked ? 1 : 0,
          type:this.communiTypes
      }).then(res=>{
          if(res.Success===true){
            if(this.isshowLauch == true)
            this.editSubmitForm();
            //获得沟通内容
            this.getContent();
            this.$message({
              message: res.Message,
              type: 'success',
              duration: 1200
            })
            this.getState();
            this.contentInput = '';
            
          }else{
            this.$message({
              message: res.Message,
              type: 'warning',
              duration: 1200
            })
          }
      }).catch(err=>{
          console.log(err);
      })      
    },
    //获取内容
    getContent(){
      axios.get('CommunicationContent',{
        key:this.DocNo,
        DocType:this.DocType
      }).then(res=>{
        this.CommunicationContentList = res;
        for(var i=0;i<this.CommunicationContentList.length;i++){
            if(this.CommunicationContentList[i].Img==''){//如果是空的
                const ac = this.acquiescenceImg;
                this.CommunicationContentList[i].Img = ac;//赋值默认头像
            }
        }    
      })
    },
    //获取type
    getState(){
      axios.get('getCommuniState',{
        key:this.DocNo,
        DocType:this.DocType,
        types:this.Type
      }).then(res=>{
        this.communiTypes = res;
        console.log(this.communiTypes,'type1');        
      }).catch(err=>{
        console.log(err);
      })
    },
    //审核提示
    checkMsg() {
      axios
        .get("checkMsg")
        .then(res => {
          this.Msg = res;
        })
        .catch(err => {
          console.log(err);
        });
    },
    //审核
    auditBudget(){
      axios
        .get('ExamineCommunication',{
          key:  this.DocNo,
          DocType:  this.DocType
        }).then(res => {
          if(res.Data === '1'){
            this.$confirm(res.Message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.ToExamineBudget();
            }).catch(() => {
                this.$message({
                type: "info",
                message: "已取消"
              });
            });
          } else if(res.Data === '2') {
            this.$message({
              type: "warning",
              message: res.Message,
              duration: 1500
            });
          }else
            this.ToExamineBudget();
        })
        .catch(err => {
          console.log(err);
        })
    },
    ToExamineBudget(){
      /* this.DocNo */
      this.checkMsg(); //审核提示
      this.$confirm(this.Msg, {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(() => {
          axios
            .get("budgetToExamine", {
              key: this.DocNo,
              type: 0 //0审核 1驳回
            })
            .then(res => {
              this.$message({
                type: "success",
                message: res
              });
              setTimeout(() => {
                this.$router.push({
                  path: "/notAudit"
                });
              }, 500);
            })
            .catch(err => {
              console.log(err);
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //驳回预算调整单提示
    rejectBudget(){
      axios
        .get('ExamineCommunication',{
          key:  this.DocNo,
          DocType:  this.DocType
        }).then(res => {
          if(res.Data === '1'){
            this.$confirm(res.Message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.IsRejectBudget();
            }).catch(() => {
                this.$message({
                type: "info",
                message: "已取消"
              });
            });
          }else
            this.IsRejectBudget();
        })
        .catch(err => {
          console.log(err);
        })
    },
    //驳回
    IsRejectBudget(){
      this.$prompt("请您输入驳回的理由", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        })
        .then(({
          value
        }) => {
          this.$message({
            type: "success",
            message: "你的驳回的理由是：" + value
          });
          axios
            .get("budgetToExamine", {
              key: this.DocNo,
              type: 1, //0审核 1驳回
              Reason: value
            })
            .then(res => {
              this.$message({
                message: res,
                type: "success"
              });
              setTimeout(() => {
                this.$router.push({
                  path: "notAudit"
                });
              }, 500);
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    },
    /**
     * @param index [当前行数]
     * @param id [选中的部门code]
     */
    changeSelect(index, id, event) {
      console.log(this.Type,index,id,"changeSelect")
      if (event) return; //如果下拉展开就不执行后面的了
      if(this.Type===0){
      // 获取费用类型方法获取费用类型方法
        this.getCostType(id, null, index).then(res => {
          this.detail[index].costTypes = res;
          // vue中对象属性改变视图不更新问题：先清空再赋值
          let detailTmp=this.detail;
          this.detail=[];
          this.detail=detailTmp

          /* if(this.Type!==2 && this.Type!==3){*/ //0添加  1修改 2查看  3有审核权限
          //this.detail[index].BorrowLine_YBL = res[0] ? res[0].ID : '';   // balance 先把费用清除掉了先
          /* } */
        });
        return;
      }
      if(this.Type===1 && this.SFBudgetItem){ 
        this.getCostType(id).then(res => {
          if(res!=null){
            this.detail[index].costTypes = res;
            if(this.Type!==2 && this.Type!==3) {//0添加  1修改 2查看  3有审核权限
              this.detail[index].BorrowLine_YBL = res[0] ? res[0].ID : '';   // balance 先把费用清除掉了先
            }
          }
        });       
      }
    },
    /**
     * @param code [部门id]
     * @param YBLID 明细ID 
     * 
     */   
    getCostType(code, YBLID, index) {
      let docDate = moment(this.docDate).format('YYYY');
      console.log(typeof docDate);
      docDate = docDate+`-0`+this.detail[index].Month.toString();
      console.log(docDate);
      if(this.SFBudgetItem){
        //费用类型
        var params = {
          id: code,
          BudgetType:this.Type===2 || this.Type===3 ? 101: this.BudgetType, //3是借款 1是报销
          /* Month: this.detail[index].Month, */ //this.MonthParams, //默认为空就是当前月份
          period: docDate,
          type: 3,
          YBLID: YBLID
          //1是新增或修改 2审核查看
        };
        return axios.post("getBudgetItem", params);
      }
      return null
    },
    ChangeMoney(index) {
      //费用类型绑定 与 预算金额
      console.log("ChangeMoney")
      const BorrowLine_YBL = this.detail[index].BorrowLine_YBL; //费用类型ID
      this.detail[index].costTypes.map(item =>
        BorrowLine_YBL == item.ID ? (this.detail[index].balance = item.YBL_ThisLeaved) : ""
      );
    },

    //月份改变的时候
    changeMonth(index,month){
      this.MonthParams = month;
      // this.detail[index].YBL_Department = '';
      // this.detail[index].BorrowLine_YBL = ''
    },

    // 撤销
    /* repeal(index, row) {
      this.$confirm("确认撤销吗?", "提示", {
        type: "warning"
      }).then(() => {
        axios
          .get("revokebudgetAdjust", {
            key: row.BA_DocNO
          })
          .then(res => {
            this.$message({
              message: res.Message,
              type: "success"
            });
            this.getList();
          });
      });
    }, */
    //删除
    handleDel(index, row) {
      this.$confirm("确认删除该记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        axios
          .get("deleBudgetAdjust", {
            key: row.BA_DocNO
          })
          .then(res => {
            this.$message({
              message: res.Message,
              type: "success"
            });
            this.getList();
          })
          .catch(err => {
            console.log(err);
          });
      });
    },
    // 获取费用承担部门数据
    bear() {
      axios.get("getDept").then(res => {
          this.bears = res;
          /* for(let i=0;i<this.detail.length;i++) {
            this.detail[i].YBL_Department = res[0].CODE;
          } */
      });
    },
    // 明细部分删除按钮
    handleDelete(index) {
      this.$confirm("确认删除该记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        this.detail.splice(index, 1);
        if (this.detail.length==0) {
          this.addlist()
        }
        this.$message({
          message: "已删除",
          type: "success"
        });
      });
    },
    Clear() {
      this.detail = [];
    },
    //外部流程图
    checkflowRow(index, rows) {
      this.checkflowRowVisible = true;
      let DocNo = rows.BA_DocNO;
      if (this.checkflowRowVisible == true) {
        if (rows.DocStatus == "新建") {
          //如果是新建状态就直接给个提示
          this.checkflowRowVisible = false;
          this.$message({
            message: "新建状态未有流程图",
            type: "warning"
          });
        } else if (rows.DocStatus == "无效") {
          //如果是无效状态也直接给个提示
          this.checkflowRowVisible = false;
          this.$message({
            message: "未找到相对应的流程图",
            type: "warning"
          });
        } else {
          //否则直接请求拿列表数据
          this.docViewloading = true;
          axios
            .get("checkFlow", {
              DocNo: DocNo, //单据编号
              DocType: 203 //类型为预算调整单
            })
            .then(res => {
              this.docRowView = res;
              setTimeout(() => {
                this.docViewloading = false;
              }, 1200);
            })
            .catch(err => {
              console.log(err);
            });
        }
      }
    },
    //内部流程图
    checkflow(){
      this.checkflowVisible = true;
      this.docViewloading = true;
      axios
        .get("checkFlow", {
          DocNo: this.DocNo, //单据编号
          DocType: 203 //类型为预算调整单
        })
        .then(res => {
          this.docView = res;
          setTimeout(() => {
            this.docViewloading = false;
          }, 1200);
        })
        .catch(err => {
          console.log(err);
        });
    },
    //打开附件列表窗口
    openUploadDialog() {
      this.dialogUploadVisible = true;
      this.getUploadList();
    },
    //附件列表
    getUploadList() {
      axios.get('UploadList', {
        key: this.DocNo,
        type: this.DocType,
        page: 1, //一页
        rows: 5000 //显示5000条
      }).then(res => {
        this.UploadList = res.rows;
      }).catch(err => {
        console.log(err);
      })
    },
    //删除附件
    DeleUpload(index,row) {
      axios.get('deleUpload', {
        key: row.ID
      }).then(res => {
        if (res.Success) {
          this.$message({
            message: res.Message,
            type: "success"
          })
          this.getUploadList();
          return
        }
        if (!res.Success) {
          this.$message({
            message: res.Message,
            type: "error"
          })
        }
      }).catch(err => {
        console.log(err);
      })
    },
    //判断是否显示预览按钮
    isShowPreview (name) {
      var fileType = ['gif','jpg','png','JPG','PNG'];
      var temp = name.substring(name.lastIndexOf('.')+1);
      if(fileType.indexOf(temp) > -1) {
        return true
      }else {
        return false
      }
    },
    //开始上传附件
    update(e) { 
      for(var i=0 ;i < e.target.files.length;i++){
        let file = e.target.files[i];
        let param = new FormData(); //创建form对象
        param.append('fileData', file); //通过append向form对象添加数据
        param.append('chunk', '0'); //添加form表单中其他数据
        param.append('key', this.DocNo); //添加form表单中其他数据
        param.append('Type', this.DocType);
        console.log(param.get('file')); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
        let config = {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }; //添加请求头
        axios.post('Upload', param, config).then(res => {
          if(res.Success){
            this.$message({
              message: `上传成功`,
              type: 'success',
              duration: 800
            });
          }else{
            this.$message({
              message: res.Message,
              type: 'warning',
              duration: 2000
            });
          }
          this.getUploadList();
        }).catch(err => {
          console.log(err)
        })
      }
    },
    preview(scoped) {
      if (this.viewer) {
        this.viewer.destroy();
      }
      this.viewer = new this.$Viewer(this.$refs["images"], {
        url: "src",
        toolbar: {
          zoomIn: {
            show: 4,
            size: "large"
          },
          zoomOut: {
            show: 4,
            size: "large"
          },
          prev: {
            show: 4,
            size: "large"
          },
          next: {
            show: 4,
            size: "large"
          },
          rotateLeft: {
            show: 4,
            size: "large"
          },
          rotateRight: {
            show: 4,
            size: "large"
          }
        }
      });
      this.$refs["images"].childNodes[scoped.$index].childNodes[0].click()
    }
    // 审核 / 申请 页面
    /* AuditAndApply() {
      this.showNum = this.$route.query.showNum;
      this.DocNo = this.$route.query.key;
      let showNum = this.showNum;
      console.log(typeof showNum,'showNum');
      console.log(showNum,'showNum');
      if (showNum === 3) {
        //2的时候是编辑页
        this.isshowEdit = true;
        this.isshowList = false;
        this.isshowAdd = false;
        //获得调整方式，预算类型
      this.getbudgetTypeAndArrangeModel();
      //获取月份
      this.getMonth();
      //获得调整方式，预算类型
      axios
        .get("budgetTypeAndArrangeModel")
        .then(res => {
          console.log(res, '获得调整方式，预算类型');
          this.AdjustModelList = res.AdjustMode; //调整方式
          this.BudgetTypeList = res.BudgetType; //	预算类型
        })
        .catch(err => {
          console.log(err);
        });
      //获取详细信息
      axios
        .get("getBudgetOperation",{key:this.DocNo})
        .then(res => {
          console.log(res,'详细信息');
          this.Type = res.Type;
          this.budgetDetail = res.entity;
          this.DocNo = this.budgetDetail.BA_DocNO;
          this.docDate = this.budgetDetail.BA_DocDate;
          this.BudgetType = this.budgetDetail.BA_BudgetType;//绑定Code
          this.AdjustModel = this.budgetDetail.BA_AdjustMode;//绑定Code
          this.describe = this.budgetDetail.BA_Abstract;
        })
        .catch(err => {
          console.log(err);
        });
      axios
        .get('getBudgetAdjustLine',{key:this.DocNo})
        .then(res => {
          this.detailTemp = res;//明细列表
          console.log(this.detailTemp,'明细列表');
          this.detail = [];
          let getCostTypePromiseAll = [];
          // 拿到明细列表后循环push' 给 detail 添加多两个字段
          for (let i = 0; i < this.detailTemp.length; i++) {
            this.detail.push({
              ...this.detailTemp[i],
              BorrowLine_BorrowMoney: this.detailTemp[i].BAL_Adjust,
              Month: this.detailTemp[i].YBL_Month,
              balance: 0,
              costTypes: []
            });

            getCostTypePromiseAll.push(
              this.getCostType(
                this.detail[i].YBL_Department, // 部门id
                this.detail[i].BorrowLine_YBL, //  明细id
                i
              )
            );
          }
        
          //  获取 费用类型
          Promise.all(getCostTypePromiseAll).then(resultArr => {
            // 循环
            for (let i = 0; i < this.detail.length; i++) {
              // 每条明细赋值费用类型数据
              this.detail[i].costTypes = resultArr[i];
              this.$set(this.detail[i], "balance", this.detail[i].YBL_ThisLeaved)
              this.$set(this.detail[i], "BorrowLine_YBL", this.detail[i].BAL_YBL)
              //  this.detail[i].BorrowLine_YBL =  Number(this.detail[i].BAL_YBL.toString())
              console.log(this.detail, "detail")
            }
          });
          //判断状态获取沟通
          if(this.communiTypes==1||this.communiTypes==2){ 
            this.dialogCommunicationVisible = true;
            this.isshowLauch = false;
            let all = [
              axios.get('CommunicationContent',{
                key:this.DocNo,
                DocType:this.DocType
              }),
              axios.get('LaunchList',{
                key:this.DocNo,
                DocType:this.DocType
              }),
            ];
            this.axios.all(all).then(
              this.axios.spread((res1,res2)=>{
                this.CommunicationContentList = res1;//获得沟通内容
                  for(var i=0;i<this.CommunicationContentList.length;i++){
                    if(this.CommunicationContentList[i].Img==''){//如果是空的
                      const ac = this.acquiescenceImg;
                      this.CommunicationContentList[i].Img = ac;//赋值默认头像
                    }
                  }
                  this.requestEmp = res2.RequestEmp;//申请人ID
                  this.LaunchList = res2.us;//获得沟通对象  
              })
            )   
          }
        })
      }
    } */
  },
  mounted() {
    this.getList();
    /* this.AuditAndApply(); */
    /* this.bear(); */
    this.checkMsg(); //审核提示
    /* console.log(this.$route.query.showNum,'this.$route.query.showNum'); */
    if(this.$route.query.showNum && this.$route.query.key){
      this.handleEdit();
    }
  },
  computed:{
    Count(){
      let sum = 0;
      for(let i of this.detail){
        sum += Number(i.BorrowLine_BorrowMoney);
      }
      //return sum      
      return Math.round(sum*100)/100;
    }
  }
};
</script>

<style scoped lang="scss">
@import "../../common/css/index.css";
.toolbar h2 {
  line-height: 36px;
  margin: 0 10px 0 0;
}
.HideTable th {
  width: 16.6666%;
}
</style>
